package orz.itrip.biz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import orz.itrip.DtoUtils;
import orz.itrip.biz.service.UserInfoService;
import orz.itrip.dto.Dto;
import orz.itrip.pojo.UserLinkUser;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/userinfo")
@Api(tags = "个人中心",description = "文档说明",hidden = true)
public class UserinfoController {

    @Resource
    private UserInfoService userInfoService;

    @PostMapping(value = "queryuserlinkuser",headers = "token")
    @ApiOperation(value = "查询联系人信息",notes = "在个人中心查询联系人信息")
    public Dto queryuserlinkuser(@RequestBody UserLinkUser userLinkUser, HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return userInfoService.queryuserlinkuser(userLinkUser);
        }
        return DtoUtils.getFalseDto("账号没有登录或者失效","100000");
    }

    @PostMapping(value = "adduserlinkuser",headers = "token")
    @ApiOperation(value = "增加联系人信息",notes = "在个人中心增加联系人信息")
    public Dto adduserlinkuser(@RequestBody UserLinkUser userLinkUser, HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return userInfoService.adduserlinkuser(userLinkUser,token);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @PostMapping(value = "modifyuserlinkuser",headers = "token")
    @ApiOperation(value = "修改联系人信息",notes = "在个人中心修改联系人信息")
    public Dto modifyuserlinkuser(@RequestBody UserLinkUser userLinkUser,HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return userInfoService.modifyuserlinkuser(userLinkUser, token);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @GetMapping(value = "deluserlinkuser",headers = "token")
    @ApiOperation(value = "删除联系人信息",notes = "在个人中心删除联系人信息")
    public Dto deluserlinkuser(@RequestParam Long[] ids,HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return userInfoService.deluserlinkuser(ids);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
}
